//
//  PostPictureViewController.m
//  SIPphone
//
//  Created by wrt on 13-11-19.
//  Copyright (c) 2013年 wrtsoft. All rights reserved.
//

#import "PostPictureViewController.h"

@interface PostPictureViewController ()

@end

@implementation PostPictureViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

//带相应参数的初始化方法  将传递过来的内容存到相应的属性里
- (id)initWithNotice:(NSString *)notice andText:(NSString *)text andTime:(NSString *)time andURL:(NSString *)url
{
    self = [super init];
    if (self)
    {
        if ([notice isEqualToString:@"notice"])
        {
            self.tempNotice = [[NSString alloc] init];
            self.tempNotice = NSLocalizedString(@"notification message", @"通知消息 Notification message");
        }
        else
        {
            self.tempNotice = [[NSString alloc] init];
            self.tempNotice = NSLocalizedString(@"advertising message", @"广告消息 Advertising message");
        }
        self.tempText = [NSString stringWithFormat:@"      %@\n\n%@",text,time];
        self.tempURL = [[NSString alloc] init];
        self.tempURL = url;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //设置对应的标题和将内容放入到文本窗口内
    self.title = self.tempNotice;
    self.textView.text = self.tempText;
    
    //将URL地址放入web控件中
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:self.tempURL]];
    [self.webView loadRequest:request];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

#pragma mark -
#pragma mark webDelegateMethod
//web控件的处理方法
//开始读的操作
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    //开始转圈等待
    [self.activityInd startAnimating] ;
}

//完成时的操作
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //停止转圈 并将其隐藏
    [self.activityInd stopAnimating];
    [self.activityInd setHidden:YES];
}

//若错误则弹出ALERT窗口
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    UIAlertView *alterview = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"image Load Error", @"图片加载错误 Image Load Error") message:NSLocalizedString(@"image Resources incorrect or network connection problems, please try again", @"图片资源不正确或者网络连接有问题，请重试 Image Resources incorrect or network connection problems, please try again")  delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"好的 OK") otherButtonTitles:nil];
    [alterview show];
}

@end
